package servlets;

import beans2.Doctor;
import db2.DoctorDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class updoctor extends HttpServlet {//修改医生信息
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Doctor doctor=null;
        DoctorDao doctorDao=new DoctorDao();
        doctor=doctorDao .getRecord((String) req.getSession().getAttribute("id"));
        doctor.setIdNumber(req.getParameter("number"));
        if(doctor==null){
            System.out.println("ERROR");
        }else{
            if(doctor.getPassword().equals(req.getParameter("old_password")));
            doctor.setPassword(req.getParameter("password"));
            doctorDao.updateRecord(doctor);
            System.out.println("修改成功");
            resp.sendRedirect("Callpatient.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
